
/**
 * Problème : on ne peut pas mettre items:[] dans le constructeur d'un form.
 *
 * http://extjs.com/forum/showthread.php?t=18570&page=2
 */
Ext.override(Ext.Container,{
    add: function(comp) {
            if(!this.items){
                this.initItems();
            }

            var a = arguments, len = a.length;

            if (len > 1) {
                for (var i = 0; i < len; i++) {
                    this.add(a[i]);
                }
                return;
            }

            if (comp) {
                var c = this.lookupComponent(this.applyDefaults(comp));
                var pos = this.items.length;

                if (this.fireEvent('beforeadd', this, c, pos) !== false && this.onBeforeAdd(c) !== false){
                this.items.add(c);

                c.ownerCt = this;
                this.fireEvent('add', this, c, pos);

            }

            return c;

        } else {
            return null;
        }
    },

    doLayout: function(){
        if (this.rendered && this.layout && this.layout.layout) {
            this.layout.layout();
        }

        if (this.items && this.items.items) {
            var cs = this.items.items;

            for (var i = 0, len = cs.length; i < len; i++) {
                var c  = cs[i];

                if (c.doLayout) {
                    c.doLayout();
                }
            }
        }
    }
});

// Some standard date/time that might be helpfull
Date.patterns = {
    ISO8601Long:"Y-m-d H:i:s",
    ISO8601Short:"Y-m-d",
    ShortDate: "n/j/Y",
    LongDate: "l, F d, Y",
    FullDateTime: "l, F d, Y g:i:s A",
    MonthDay: "F d",
    ShortTime: "g:i A",
    LongTime: "g:i:s A",
    SortableDateTime: "Y-m-d\\TH:i:s",
    UniversalSortableDateTime: "Y-m-d H:i:sO",
    YearMonth: "F, Y"
};

// Returns true if the array contains the needle
Array.prototype.contains = function(needle, strict) {
    var found = false, key, strict = !!strict;

    for (key in this) {
        if ((strict && this[key] === needle) || (!strict && this[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
};

// Javascript implementation of the PHP implode function
Array.prototype.implode = function(glue) {
    var string      = '';
    var separator   = '';

    for (key = 0 ; key < this.length ; key++) {
        string      = string + separator + this[key];
        separator   = glue;
    }

    return string;
}

// Capitalize the first letter of a string, minimize the other letters
String.prototype.ucfirst = function() {
    return this.charAt(0).toUpperCase() + this.substr(1);
};